package com.happy.cat.project.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.happy.cat.framework.redis.MybatisRedisCache;
import com.happy.cat.project.system.domain.UserGiftDetail;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 用户赠送礼物日志Mapper接口
 *
 * @author verne
 * @date 2020-08-15
 */
@Repository
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface UserGiftDetailMapper extends BaseMapper<UserGiftDetail> {

    /**
     * 统计查询
     * @param receiverId
     * @return
     */
    @Select("SELECT COUNT(id) AS counts, gift_id, sum(gift_number) AS gifts, GROUP_CONCAT(DISTINCT `source`) AS text FROM user_gift_detail WHERE receiver_id = ${receiverId} GROUP BY gift_id")
    List<Map<String, Object>> groupByGiftToReceiverId(@Param("receiverId") Long receiverId);

}
